package com.concurrent.chapter6.concurrent01;

import java.util.LinkedList;
import java.util.List;
import java.util.Random;

public class NotUseThreadPool {
	public static void main(String[] args) {
		long startTime = System.currentTimeMillis();
		final List<Integer> list = new LinkedList<>();
		final Random random = new Random();
		int count = 10000;
		//不使用线程池，每次创建一个线程
		for (int i = 0; i < count; i++) {
			Thread thread = new Thread(new Runnable() {
				
				@Override
				public void run() {
					list.add(random.nextInt());
					System.out.println(Thread.currentThread().getName());
				}
			});
			thread.start();
			try {
				thread.join();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		System.out.println(System.currentTimeMillis() - startTime);
		System.out.println(list.size());
	}
}
